package calvin.study.rabbitmq.service.impl.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import calvin.study.rabbitmq.dao.ProductDao;
import calvin.study.rabbitmq.model.product.Product;
import calvin.study.rabbitmq.service.product.IProductService;

@Service
public class ProductService implements IProductService {

	@Autowired
	private ProductDao productDao;

	@Transactional
	public void updateProductNumber(Integer productId) throws Exception {

		Product product = productDao.getProductById(productId);
		if (null == product) {
			throw new RuntimeException("该商品不存在");
		}

		if (product.getProductNumber() <= 0) {
			throw new RuntimeException("该商品库存不足");
		}
		
		productDao.updateProductNumber(productId);
	}
}
